import request from "@/utils/request";
import { Course, CourseDetailResponse, CourseSubject, CourseSubjectResponse } from "./type";

export const getCourseListByUserId = (userId: string) => {
    return request.get(`/classroom/course/list/${userId}`);
}

export function uploadCourseCover(formData: FormData) {
  return request.post("/classroom/course/cover/upload", formData, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}

export const createCourse = (course: Course) => {
  return request.post("/classroom/course/create", course);
};

export const deleteCourse = (courseId: string) => {
  return request.delete(`/classroom/course/delete/${courseId}`);
}

export function getCourseDetail(courseId: string) {
  return request.get<CourseDetailResponse>(`/classroom/course/detail/${courseId}`);
}


export const addUser = (courseId: string, userId: string, type: number) => {
  return request.get(`/classroom/users/add/${courseId}/${userId}/${type}`)
}

// 移除用户（学生/助教/教师）
export const removeUser = (courseId: string, userId: string) => {
  return request.get(`/classroom/users/remove/${courseId}/${userId}`)
}

// 获取某课程下的用户列表（学生/助教/教师）
export const getUserList = (courseId: string, type: number) => {
  return request.get(`/classroom/users/list/${courseId}/${type}`)
}

export function updateCourseSubjects(data: CourseSubject) {
  return request.put<CourseSubjectResponse>("course/subjects/update/subjects", data);
}

export function createCourseSubjects(data: CourseSubject) {
  return request.post<CourseSubjectResponse>("/course/subjects/create/subjects", data);
}

export function getCourseSubjectsList(courseId: string) {
  return request.get<CourseSubjectResponse>(`/course/subjects/list/subjects/${courseId}`);
}

export function deleteCourseSubjects(courseSubjectsId: string) {
  return request.delete<CourseSubjectResponse>(`/course/subjects/delete/subjects/${courseSubjectsId}`);
}

export function getSubjectList() {
  return request.get("/subject/list");
}

